package com.lxw.manage_cms.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //交换机的名称
    public static final String EX_ROUTING_CMS_POSTPAGE="ex_routing_cms_postpage";
    @Value("${yh.mq.queue}")
    private String queueName;
    @Value("${yh.mq.routeKey}")
    private String routeKey;
    //创建对列
    @Bean
    public Queue cms_post_queue_01(){
        return new Queue(queueName, false, false, false, null);
    }
    //声明交换机 类型为direc
    @Bean()
    public DirectExchange ex_routing_cms_postpage() {
        return new DirectExchange(EX_ROUTING_CMS_POSTPAGE);
    }

//    交换机和消息对列绑定
    @Bean
    public Binding BINDING_QUEUE_INFORM_SMS(){
        return BindingBuilder.bind(cms_post_queue_01()).to(ex_routing_cms_postpage()).with(routeKey);
    }

}
